package com.carter.springframework.core.io;

import cn.hutool.core.lang.Assert;

import java.net.MalformedURLException;
import java.net.URL;

public class DefaultResourceLoader implements ResourceLoader{
    @Override
    public Resource getResource(String location) {
        Assert.notNull(location);
        if (location.startsWith(CLASSPATH_URL_PREFIX)){
            return new ClasspathResource(location);
        }else {
            try{
                URL url = new URL(location);
                return new UrlResource(url);
            }catch (MalformedURLException e) {
                return new FileSystemResource(location);
            }
        }
    }

    @Override
    public ClassLoader getClassLoader() {
        return null;
    }
}
